package com.businesswebsite.businesswebsite.FormalWebExplot.Service.impl.Product;

import com.businesswebsite.businesswebsite.FormalWebExplot.Dao.Product.ProductDao;
import com.businesswebsite.businesswebsite.FormalWebExplot.Entity.Product;
import com.businesswebsite.businesswebsite.FormalWebExplot.Service.Product.ProductService;
import com.businesswebsite.businesswebsite.FormalWebExplot.Utils.Renum;
import com.businesswebsite.businesswebsite.FormalWebExplot.Utils.Result;
import com.businesswebsite.businesswebsite.FormalWebExplot.Utils.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class ProductImpl implements ProductService {
    @Autowired
    ProductDao productDao;
    @Override
    public Integer addProduct(Map<String, Object> params){
        Integer product = productDao.addProduct(params);
        if (product > 0){
            return product;
        }
        return null;
    }

    @Override
    public List<Product> getProduct() {
        List<Product> product = productDao.getProduct();
        if(product == null){
            return null;
        }
        return product;
    }

    @Override
    public Integer delProduct(String pro_id) {
        Product productById = getProductById(pro_id);
        if(productById == null){
            return 0;
        }
        Integer del = productDao.delProduct(pro_id);
        return del;
    }

    @Override
    public Product getProductById(String pro_id) {
        if(pro_id == null){
            return null;
        }
        Product product = productDao.getProductById(pro_id);
        if(product == null){
            return null;
        }
        return product;

    }
}
